<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
<title>Hello APP</title>
<link rel="stylesheet" type="text/css" href="../css/swiper.css" />
<link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
<link rel="stylesheet" type="text/css" href="../css/aui.css" />
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<style>
#mainImg .swiper-slide{
	height: 100vh;
	background-position: center top;
	background-repeat: no-repeat;
	background-size: 100% auto;
}
	.swiper-pagination-bullet {
		background: none;
		border: 1px solid #979797;
		opacity: 1;
	}
	.swiper-pagination-bullet-active {
		background: #444;
		border-color: #444;
	}
	.swiper-container-horizontal > .swiper-pagination-bullets {
		bottom: 4.45rem;
	}
	.wxBtn{
		position: fixed;
		bottom: 1rem;
		width: 100%;
		color: #fff;
		z-index: 15
	}
	.wxBtn .comBtmBtn{
		width: 8.5rem;
		margin: 0 auto;
	}
</style>
</head>
<!-- <body class="">
		<div class="bg-white shadow">
			<div class="swiper-container" id="mainImg">
				<div class="swiper-wrapper">
					<div class="swiper-slide" style="background-image: url(../image/guide/1.jpg);"></div>
					<div class="swiper-slide" style="background-image: url(../image/guide/2.jpg);"></div>
					<div class="swiper-slide" style="background-image: url(../image/guide/3.jpg);"></div>
				</div>
				<div class="swiper-pagination"></div>
			</div>
		</div>
		<div class="wxBtn">
			<div class="comBtmBtn aui-font-size-14 radius" tapmode onclick="wxLogin()">微信登录</div>

		</div>

</body> -->
<script type="text/javascript" src="../script/import.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/swiper.min.js"></script>
<script type="text/javascript">
var USER_INFO;
apiready = function(){
	api.parseTapmode();
	api.addEventListener({
		name: 'keyback'
	}, function(ret, err) {
		api.closeWidget();
	});
};
topSliderInit()
//顶部图片滑动
function topSliderInit(){
	new Swiper('#mainImg',{
		speed: 600,
		autoplay: false,
		followFinger: false,
		pagination: {
			el: '#mainImg .swiper-pagination',
		},
	})
}

// 打开首页
function openHome(){
	api.openFrame({
	    name: '../index',
	    url: '../index.html',
	    rect: {
	        x: 0,
	        y: 0,
	        w: api.winWidth,
	        h: api.winHeight
	    },
	    pageParam: {
	        name: 'test'
	    },
	    bounces: false,
	});
}

//微信登录
function wxLogin(){
	var wx = api.require('wx');
	wx.auth({
		apiKey: ''
	}, function(result, err) {
		if (result.status) {
			//获取openid
			wx.getToken({
				apiKey: '',
				apiSecret: '',
				code: result.code
			}, function(res, err) {
				 console.log(JSON.stringify(res));
				if (res.status) {
					wx.getUserInfo({
					    accessToken: res.accessToken,
					    openId: res.openId
					}, function(mes, err) {
					    if (mes.status) {
					         console.log(JSON.stringify(mes));
									api.ajax({
										url: BASE_URL + 'App/User/userLogin',
										method: 'post',
										data: {
											values: {
												wx_openid: mes.openid,
												unionid: mes.unionid
											}
										}
									},function(ret,err){
										if (ret) {
											 console.log(JSON.stringify(ret));
											if(ret.code == -1){
												//未注册用户
												wx_openId = mes.openid;
												wx_unionid = mes.unionid;
												wx_nickname = mes.nickname;
												wx_headimgurl = mes.headimgurl;
												wx_sex = mes.sex;
												if( wx_openId && wx_unionid ){
													api.openWin({
														name: 'login',
														url: 'login.html',
														bounces: false,
														pageParam: {
															wx_openid: wx_openId,
															unionid: wx_unionid,
															nickname: wx_nickname,
															headimgurl: wx_headimgurl
														}
													});
												}else{
													toast('系统异常');
												}
											} else{
												//已注册 提示登录成功
												USER_INFO = ret.data;
												loginSuccess();
											}
										} else {
											toast('系统异常');
										}
									});
					    } else {
								toast('系统异常');
					    }
					});
				} else {
					toast('系统异常');
				}
			});
		} else {
			toast('系统异常');
		}
	});
}
function loginSuccess(){
    toast('登录成功');
    api.setPrefs({
        key: 'userId',
        value: USER_INFO.userid
	});
    api.setPrefs({
        key: 'userInfo',
        value: USER_INFO
    });
    api.sendEvent({
        name: 'loginSuccessEvent'
    });
    setTimeout(function(){
        api.closeToWin({
            name: 'root'
        });
    },1000);
}
</script>
</html>
